/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package network;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Administrator
 */
public class codingUserID {

    public static Map<String, Integer> old2new = new HashMap<String, Integer>();
    public static String folder = Config.folderName;
    public static String uid = Config.uid;
    public static String filename = Config.path + "myFriendsIDs&Names" + ".txt";
    public static String network = Config.path + "outNet" + ".txt";
    public static String outputfilename = Config.path + "myFriendsIDs&Names_recoded" + ".txt";
    public static String outputnetwork = Config.path + "outNet_recoded" + ".txt";

    public static void main(String[] args) throws IOException {
        old2new.put(uid, 1);
        codeF();
        codeNetwork();
    }

    public static void codeNetwork() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(network)));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputnetwork)));
        String line = reader.readLine();
        String a[];
        while (line != null) {
            if (line.isEmpty()) {
                line = reader.readLine();
            } else {
                a = line.split(" ");
                int in = old2new.get(a[0]);
                int out = old2new.get(a[1]);
                writer.write(in + " " + out + "\r\n");
                line = reader.readLine();
            }
        }
        writer.close();
        reader.close();
    }

    public static void codeF() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
        String line = reader.readLine();
        String a[];
        int newid = 1;
        while (line != null) {
            if (!line.isEmpty()) {
                a = line.split(" ");
                {
                    newid += 1;
                    old2new.put(a[0], newid);
                }
                line = reader.readLine();
            } else {
                line = reader.readLine();
                continue;
            }
        }
        reader.close();
    }
}
